//
//  NavTitleView.m
//  Growth
//
//  Created by 洪波 陈 on 5/28/12.
//  Copyright (c) 2012 MEETStudio. All rights reserved.
//

#import "NavTitleView.h"

#import "SDImageView+SDWebCache.h"

@implementation NavTitleView

- (id)initWithTitle:(NSString *)titleStr
{
    static float maxWidth = 160;
    static float imageWidth = 26.0;
    static float distance = 5.0;
    
    float labelWidth = 0;
    
    UIFont *font = [UIFont boldSystemFontOfSize:20];
    CGSize size = CGSizeMake(maxWidth -imageWidth -distance,30);
    CGSize labelsize = [titleStr sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap]; 
    
    CLog(@"title label width %f", labelsize.width);
    
    labelWidth = labelsize.width;
    labelWidth = labelWidth >(maxWidth - imageWidth -distance)? maxWidth -imageWidth -distance:labelWidth;
    
    self = [super initWithFrame:CGRectMake(0, 0, imageWidth +labelWidth +distance , 30)];
    
    
    if (self) {
        // Initialization code
        NSString *tAttachmentId = [[NSUserDefaults standardUserDefaults] valueForKey:BABY_ATTACHMENTID];
        
        
        
//        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.frame)/2 -imageWidth /2, imageWidth, imageWidth)];
//        imageView.layer.cornerRadius =13;
//        imageView.clipsToBounds = YES;
//        [imageView setContentMode:UIViewContentModeScaleAspectFill];
//        [imageView setBackgroundColor:[UIColor clearColor]];
//        
//        NSString *string=[NSString stringWithFormat:@"%@%@/%@/100x100",BASEURL,@"/commons/attachment/download",tAttachmentId];
//        NSURL *url = [NSURL URLWithString:string];	
//        //[imageView setImageWithURL:url imageType:kImageCache_Content_Icon];
//        
//         [imageView setImageWithURL:url refreshCache:NO placeholderImage:[UIImage imageNamed:@"nophoto_bb_iphone.png"] imageType:kImageCache_Content_Icon]; 
//        
//        [self addSubview:imageView];
//        
//        [imageView release];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageWidth +distance, 0, labelWidth, 30)];
        titleLabel.text = titleStr;
        [titleLabel setFont:font];
        [titleLabel setTextColor:[UIColor whiteColor]];
        [titleLabel setBackgroundColor:[UIColor clearColor]];
        [titleLabel setTextAlignment:UITextAlignmentLeft];
        [self addSubview:titleLabel];
        [titleLabel release];
        
        
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
               
        
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
